<?php
class Data_Model_KyThiMapper extends Data_Model_DataMapperAbstract
{
	protected static $_instance = null;
	// dung de phan trang
	private $_paginator = null;
	
	public function searchByMakhoahoc($id)
	{
		$db = $this->getDb();
		$selectKythi = $db->select()
							->from('tbl_kythi')
							->where('MaKhoaHoc = ?',$id);
		$kythi = $db->fetchRow($selectKythi);
	
		return $this->_populate($kythi);
	
	}
	public function searchById($id)
	{
		$db = $this->getDb();
		$selectKythi = $db->select()
						->from('tbl_kythi')
						->where('MaKyThi = ?',$id);
		$kythi = $db->fetchRow($selectKythi);
			
		return $this->_populate($kythi);
	}
	// hien thi
	public function _populate($data)
	{
		$obj = new Data_Model_KyThi();
		$obj->setId($data['MaKyThi']);
		$obj->setMakhoahoc($data['MaKhoaHoc']);
		$obj->setNgaythi($data['NgayThi']);
		$obj->setGhichu($data['GhiChu']);
		
		return $obj;		
	}
	protected function _insert(Data_Model_DomainObjectAbstract $obj){
	
		$db = $this->getDb();
		$data =array(
				'MaKhoaHoc' => $obj->getMakhoahoc(),
				'NgayThi' => $obj->getNgaythi(),
				'GhiChu' => $obj->getGhichu()
				);
		$db->insert('tbl_kythi',$data);
	}
	protected function _update(Data_Model_DomainObjectAbstract $obj){
		
		$db = $this->getDb();
		$data =array(
				'MaKhoaHoc' => $obj->getMakhoahoc(),
				'NgayThi' => $obj->getNgaythi(),
				'GhiChu' => $obj->getGhichu()
		);
		$where = $db->quoteInto('MaKyThi = ?', $obj->getId());
		$db->update('tbl_kythi',$data,$where);
	}
	
	public function delete($id)
	{
		$db = $this->getDb();
		$where = $db->quoteInto('MaKyThi = ?',$id);
		$db->delete('tbl_kythi',$where);
	}
	
	// Goi chinh no
	
	public static function getInstance()
	{
		if(null === self::$_instance)
		{
			self::$_instance = new self();				
		}
		return self::$_instance;
	}
}